<?  //common functions

    /**
     *  Returns current script name
     */
    function script_name() {
        $scriptname = @$_SERVER['REQUEST_URI'];
        if(!isset($scriptname)) {
            $scriptname = @$GLOBALS['SCRIPT_NAME'];
        }
        return $scriptname;
    }

    /**
     *  Returns document root path
     */
    function root_path() {
        $path = @$_SERVER['DOCUMENT_ROOT'];
        if (substr($path, strlen($path) - 1, strlen($path)) == '/') {
            $path = substr($path, 0, strlen($path) - 1);
        }
        return $path;
    }

    /**
     *  Splits path to parts. Returns array of path parts.
     */
    function split_path($path) {
        $result = array();
        //split URL to parts
        $url_parts = parse_url($path);
        //print_r($url_parts); echo('<br/>');
        $path = $url_parts['path'];
        //split path to parts
        $path_parts = pathinfo($path);
        //print_r($path_parts); echo('<br/>');
        $basename = $path_parts['basename'];
        $path = $path_parts['dirname'];
        //get path parts
        $parts = explode('/', $path);
        foreach ($parts as $part) {
            if ($part != '') {
                $result[] = $part;
            }
        }
        //get basename without extension
        if ($path_parts['extension'] != '') {
            $basename = substr($basename, 0, - strlen($path_parts['extension']) - 1);
        }
        $result[] = $basename;

        return $result;
    }

    /**
     *  Returns TRUE if str1 contains str2 as substring
     */
    function contains($str1, $str2) {
        return strpos($str1, $str2) !== FALSE;
    }

    /**
     *  Returns TRUE if str1 ends with str2.
     */
    function endsWith($str1, $str2) {
        $pos = strpos($str1, $str2);
        return $pos === strlen($str1) - strlen($str2);
    }

?>